package com.woniuxy.wd.dao.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Properties;

import com.woniuxy.wd.dao.CountryDAO;


public class MSSQLFactory extends DAOFactory {
	
	public DAOInterface getInstance(String name){
		Properties pro = new Properties();
		//初始化接口
		DAOInterface dao = null;
		try {
			//读取properties文件
			pro.load(MSSQLFactory.class.getResourceAsStream("/config.properties"));
			//获取名字
			String className = pro.getProperty(name);
			//类反射
			Class clzz = Class.forName(className);
			//加载类
			ClassLoader loader = clzz.getClassLoader();  
			//获取clzz的接口
		    Class<?>[] interfaces = clzz.getInterfaces(); 
		    //处理clzz反射
		    InvocationHandler interceptor = new Interceptor(clzz.newInstance());
		    //处理这个新的实例
			dao = (DAOInterface) Proxy.newProxyInstance(loader,interfaces,interceptor);
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return dao;
	}

}
